<!DOCTYPE html>
<?php
require 'execute/auth.php';
require 'config/config.php';

mydb_connect();
?>
<!--[if lt IE 7 ]><html lang="en" class="ie6 ielt7 ielt8 ielt9"><![endif]--><!--[if IE 7 ]><html lang="en" class="ie7 ielt8 ielt9"><![endif]--><!--[if IE 8 ]><html lang="en" class="ie8 ielt9"><![endif]--><!--[if IE 9 ]><html lang="en" class="ie9"> <![endif]--><!--[if (gt IE 9)|!(IE)]><!--> 
<html lang="en"><!--<![endif]--> 
	
<!-- Mirrored from wbpreview.com/previews/WB0070A9H/index.htm by HTTrack Website Copier/3.x [XR&CO'2013], Wed, 22 Jan 2014 10:30:52 GMT -->
<head>
		<meta charset="utf-8">
		<title>Dashboard - TechAfghanistan</title>

<meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="keywords" content="opensource rich wysiwyg text editor jquery bootstrap execCommand html5" />
    <meta name="description" content="This tiny jQuery Bootstrap WYSIWYG plugin turns any DIV into a HTML5 rich text editor" />
    <link rel="apple-touch-icon" href="http://mindmup.s3.amazonaws.com/lib/img/apple-touch-icon.png" />
    <link rel="shortcut icon" href="http://mindmup.s3.amazonaws.com/lib/img/favicon.ico" >
    <link href="js/external/google-code-prettify/prettify.css" rel="stylesheet">
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
    <link href="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" rel="stylesheet">
		<link href="http://netdna.bootstrapcdn.com/font-awesome/3.0.2/css/font-awesome.css" rel="stylesheet">
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
    <script src="http://malsup.github.io/jquery.form.js"></script>
		<script src="js/external/jquery.hotkeys.js"></script>
    <script src="http://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
    <script src="js/external/google-code-prettify/prettify.js"></script>
		<link href="css/index.css" rel="stylesheet">
    <script src="js/bootstrap-wysiwyg.js"></script>


<script type="text/javascript">
$(function(){
	$(".editPost").on("click",function(){
jQuery.param.querystring(window.location.href, 'valueA=321&valueB=123');
	});
});
</script>
		<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	<style type="text/css">
 		#editor {
 			overflow:scroll; 
 			max-height:250px;
 			width: 650px;
 		}
	</style>	
	<script type="text/javascript">	
		$(function(){
			$('#show_link').click(function(event) {
  $('html').one('click',function() {
				$("#link").hide();
  });

  event.stopPropagation();
});
		});
		</script>	
	<link href="css/site.css" rel="stylesheet">
	<script type="text/javascript">
		$(function(){
			$("#show_link").on("click",function(){
				$("#link").show();
			});

			$("#editor").on("keyup",function(){
				$(".content").html($(this).html());
			});
		});
	</script>
	

		<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script><![endif]-->
	</head>
	<body>
		<div class="container">
			<div class="navbar">
				<div class="navbar-inner">
				<div class="container">
						<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a> <a class="brand" href="#">TechAfghanistan</a>
						<div class="nav-collapse">
							<ul class="nav">
									<li class="dropdown">
									<a href="help.html" class="dropdown-toggle" data-toggle="dropdown">Tours <b class="caret"></b></a>
									<ul class="dropdown-menu">
										<li>
											<a class="addLink" href="help.html">Introduction Tour</a>
										</li>
										<li>
											<a href="help.html">Project Organisation</a>
										</li>
										<li>
											<a href="help.html">Task Assignment</a>
										</li>
										<li>
											<a href="help.html">Access Permissions</a>
										</li>
										<li class="divider">
										</li>
										<li class="nav-header">
											Files
										</li>
										<li>
											<a href="help.html">How to upload multiple files</a>
										</li>
										<li>
											<a href="help.html">Using file version</a>
										</li>
									</ul>
								</li>
							</ul>
							<form class="navbar-search pull-right" action="#">
								<input type="text" class="search-query span2" placeholder="Search" />
							</form>
							<ul class="nav pull-right">
								<li>
									<a href="profile.html"><i class="fa fa-user"> username</i></a>
								</li>
								
							</ul>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="span3">
					<div class="well" style="padding: 8px 0;">
						<ul class="nav nav-list">
							<li class="nav-header">
								TechAfghanistan
							</li>
							<li>
								<a href="index.php"><i class="icon-home"></i> Dashboard</a>
							</li>
							<li>
								<a href="news.php"><i class="icon-home"></i> Posts</a>
							</li>
						</ul>
					</div>
				</div>
			<div class="span9">
				<?php if(isset($_GET['delete']) && $_GET['delete']=="success"){
					?>
					<div class="alert alert-success">Post deleted successfully	</div>
					<?php
				} 

				?>
				<?php if(isset($_GET['publish']) && $_GET['publish']=="success"){
					?>
					<div class="alert alert-success">Post published successfully</div>
					<?php
				} 

				?>
				<?php if(isset($_GET['update']) && $_GET['update']=="success"){
					?>
					<div class="alert alert-success">Post updated successfully</div>
					<?php
				} 

				?>
					<h2>
						Posts
					</h2>
					<a class="toggle-link" href="#new-file"><i class="icon-plus"></i> Publish New</a>
					<form id="new-file" action="execute/add_news.php" method="post" enctype="multipart/form-data" class="form-horizontal hidden">
						<fieldset>
							<legend>New Post</legend>
							<div class="control-group">
								<label class="control-label" for="textarea">Title</label>
								<div class="controls">
									<input type="text" class="input-xlarge" name="title" id="input01" />
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Author</label>
								<div class="controls">
									<input type="radio" id="r-self" name="author_who" value="self" checked> Self  &nbsp; &nbsp; <input type="radio" id="r-other" name="author_who" value="other"> Other <br>
									<div class="other-div" style="margin-top: 10px; display:none;">
										<select name="other-author-id" id="other-author-id">
											<option value="">Choose an author...</option>
											<?php 
												$otherauthor = $conn->query("SELECT * FROM `users` WHERE `role`='ext_author'");
												while($otherauthor_row = $otherauthor->fetch()){
													$twitter = $conn->query("SELECT `twitter_id` FROM `user_authors` WHERE id = '".$otherauthor_row['id']."'");
													$twitter_row = $twitter->fetch();
											?>
											<option value="<?php echo $otherauthor_row['id']; ?>"><?php echo $otherauthor_row['firstname'] . " " . $otherauthor_row['lastname'] . " - " . $twitter_row[0]; ?></option>
											<?php } ?>
										</select> Not found in list? <a href="#addNewAuthor" role="button" data-toggle="modal">+ Add New</a>
										<div class="alert alert-success" id="success-author" style="display:none;">Author Added Successfully</div>
									</div>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Section</label>
								<div class="controls">
									<select name="section" class="input-xlarge">
										<option value="news">News</option>
										<option value="article">Article</option>
										<option value="howto">How to</option>
										<option value="review">Review</option>										
										<option value="opinion">Opinion</option>
									</select>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Category</label>
								<div class="controls">
									<select name="category" class="input-xlarge">
										<option value="">Choose a category...</option>
										<?php 
											$select_cat = $conn->query("SELECT * FROM news_categories ORDER BY category_name");
											while($row_cat = $select_cat->fetch()){
										?>
											<option value="<?php echo $row_cat['id']; ?>"><?php echo $row_cat['category_name']; ?></option>
										<?php } ?>
									</select> 
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Description</label>
								<div class="controls">
									<textarea class="input-xlarge" name="description"></textarea>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Video (If any)</label>
								<div class="controls">
									<textarea class="input-xlarge" name="video"></textarea>
									<p class="help-block">Paste video URL (Only YouTube is Supported).</p>
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Image</label>
								<div class="controls">
									<input type="file" class="input-xlarge" name="img_name" id="input03" />
								</div>
							</div>
							<div class="control-group">
								<label class="control-label" for="textarea">Content</label>
								<div class="controls">
									<div id="alerts"></div>
							    <div class="btn-toolbar" data-role="editor-toolbar" data-target="#editor">
							      <div class="btn-group">
							        <a class="btn dropdown-toggle" data-toggle="dropdown" title="Font Size"><i class="icon-text-height"></i>&nbsp;<b class="caret"></b></a>
							          <ul class="dropdown-menu">
												<li><a data-edit="fontSize 7"><font size="7">Very Huge</font></a></li>
							          <li><a data-edit="fontSize 5"><font size="5">Huge</font></a></li>
							          <li><a data-edit="fontSize 3"><font size="3">Normal</font></a></li>
							          <li><a data-edit="fontSize 1"><font size="1">Small</font></a></li>
							          </ul>
							      </div>
							      <div class="btn-group">
							        <a class="btn" data-edit="bold" title="Bold (Ctrl/Cmd+B)"><i class="icon-bold"></i></a>
							        <a class="btn" data-edit="italic" title="Italic (Ctrl/Cmd+I)"><i class="icon-italic"></i></a>
							        <a class="btn" data-edit="strikethrough" title="Strikethrough"><i class="icon-strikethrough"></i></a>
							        <a class="btn" data-edit="underline" title="Underline (Ctrl/Cmd+U)"><i class="icon-underline"></i></a>
							      </div>
							      <div class="btn-group">
							        <a class="btn" data-edit="insertunorderedlist" title="Bullet list"><i class="icon-list-ul"></i></a>
							        <a class="btn" data-edit="insertorderedlist" title="Number list"><i class="icon-list-ol"></i></a>
							        <a class="btn" data-edit="outdent" title="Reduce indent (Shift+Tab)"><i class="icon-indent-left"></i></a>
							        <a class="btn" data-edit="indent" title="Indent (Tab)"><i class="icon-indent-right"></i></a>
							      </div>
							      <div class="btn-group">
							        <a class="btn" data-edit="justifyleft" title="Align Left (Ctrl/Cmd+L)"><i class="icon-align-left"></i></a>
							        <a class="btn" data-edit="justifycenter" title="Center (Ctrl/Cmd+E)"><i class="icon-align-center"></i></a>
							        <a class="btn" data-edit="justifyright" title="Align Right (Ctrl/Cmd+R)"><i class="icon-align-right"></i></a>
							        <a class="btn" data-edit="justifyfull" title="Justify (Ctrl/Cmd+J)"><i class="icon-align-justify"></i></a>
							      </div>
							      <div class="btn-group">
									  	<a id="show_link" class="btn" title="Hyperlink"><i class="icon-link"></i></a>
										    <div class="dropdown-menu input-append" id="link" style="display:none;margin-left: -30px;padding: 0px;">
											    <input class="span2" placeholder="URL" type="text" data-edit="createLink"/>
											    <button class="btn" type="button">Add</button>
								        </div>
							        <a class="btn" data-edit="unlink" title="Remove Hyperlink"><i class="icon-cut"></i></a>

							      </div>
							      
							      <div class="btn-group">
							        <a class="btn" title="Insert picture (or just drag & drop)" id="pictureBtn"><i class="icon-picture"></i></a>
							        <input type="file" data-role="magic-overlay" data-target="#pictureBtn" data-edit="insertImage" />
							      </div>
							      <div class="btn-group"><input type="text" data-edit="inserttext" id="voiceBtn" x-webkit-speech="">
							      	</div>
							    </div>

							    <div id="editor">
							    </div>
							    <textarea name="content" class="content hidden"></textarea>
								</div>
							</div>
							<input type="hidden" name="isSelf" id="isSelf" value="yes">
							<div class="form-actions">
								<button type="submit" name="submit" class="btn btn-primary">Publish News</button> <button type="reset" class="btn">Cancel</button>
							</div>
						</fieldset>
					</form>
					<table class="table table-bordered">
						<thead>
							<tr>
								<th style="width:30%">
									Title
								</th>
								<th style="width:50%">
									Description
								</th>
								<th>
									Publish Date
								</th>
								<th>
									Actions
								</th>
								
								
								</tr>
							
						</thead>
						<tbody>
							<?php
								$authorSelectQry = $conn->query("SELECT * FROM `news` WHERE physical_author_id = '".$_SESSION['USER_ID']."' ORDER BY pub_date DESC");
								
								while($authorSelectRow=$authorSelectQry->fetch()){
								?>
								<tr><td><?php echo $authorSelectRow['title']; ?></td><td><?php echo $authorSelectRow['description']; ?></td><td><?php echo $authorSelectRow['pub_date']; ?></td><td><a href="http://tech.af/author/news_edit.php?id=<?php echo $authorSelectRow['id']; ?>">Edit</a> | <a href="http://tech.af/author/execute/remove_post.php?id=<?php echo $authorSelectRow['id']; ?>">Delete</a></td></tr>
									<?php
								}
							?>
						</tbody>
						
					</table>
					
					
				</div>
			</div>
		</div>	
		<!-- Add new author -->
		<div id="addNewAuthor" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		  <div class="modal-header">
		    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
		    <h3 id="myModalLabel">Add New Author</h3>
		  </div>
		  <div class="modal-body">
		    <form class="form-horizontal" id="addNewAuthorForm" action="execute/add_author.php" enctype="multipart/form-data" method="POST">
		<fieldset>
		<div class="control-group">
		  <label class="control-label" for="twitter_id">Twitter ID</label>
		  <div class="controls">
		    <input id="twitter_id" name="twitter_id" type="text" placeholder="e.g. @example" class="input-xlarge" required>
		    <p class="help-block">* This will be used as the unique identifier (ID) for this author.</p>
		  </div>
		</div>

		<!-- Text input-->
		<div class="control-group">
		  <label class="control-label" for="firstname">First Name</label>
		  <div class="controls">
		    <input id="firstname" name="firstname" type="text" placeholder="e.g. Johm" class="input-xlarge" required>
		    
		  </div>
		</div>
		<div class="control-group">
		  <label class="control-label" for="lastname">Last Name</label>
		  <div class="controls">
		    <input id="lastname" name="lastname" type="text" placeholder="e.g. Smith" class="input-xlarge" required>
		    
		  </div>
		</div>

		<!-- Textarea -->
		<div class="control-group">
		  <label class="control-label" for="bio">Bio</label>
		  <div class="controls">                     
		    <textarea id="bio" name="bio"></textarea>
		  </div>
		</div>

		<!-- Text input-->
		<div class="control-group">
		  <label class="control-label" for="facebook_url">Facebook Profile</label>
		  <div class="controls">
		    <input id="facebook_url" name="facebook_url" type="text" placeholder="e.g. http://facebook.com/exampleid" class="input-xlarge">
		    
		  </div>
		</div>

		<!-- Text input-->
		<div class="control-group">
		  <label class="control-label" for="linkedin_url">LinkedIn Profile</label>
		  <div class="controls">
		    <input id="linkedin_url" name="linkedin_url" type="text" placeholder="e.g. http://linkedin.com/exampleid" class="input-xlarge">
		    
		  </div>
		</div>

		<!-- File Button --> 
		<div class="control-group">
		  <label class="control-label" for="image">Image</label>
		  <div class="controls">
		    <input id="image" name="image" class="input-file" type="file">
		  </div>
		</div>

		</fieldset>


  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
  </form>
</div>	
    <script>
  $(function(){
    function initToolbarBootstrapBindings() {
      var fonts = ['Serif', 'Sans', 'Arial', 'Arial Black', 'Courier', 
            'Courier New', 'Comic Sans MS', 'Helvetica', 'Impact', 'Lucida Grande', 'Lucida Sans', 'Tahoma', 'Times',
            'Times New Roman', 'Verdana'],
            fontTarget = $('[title=Font]').siblings('.dropdown-menu');
      $.each(fonts, function (idx, fontName) {
          fontTarget.append($('<li><a data-edit="fontName ' + fontName +'" style="font-family:\''+ fontName +'\'">'+fontName + '</a></li>'));
      });
      $('a[title]').tooltip({container:'body'});
    	$('.dropdown-menu input').click(function() {return false;})
		    .change(function () {$(this).parent('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle');})
        .keydown('esc', function () {this.value='';$(this).change();});

      $('[data-role=magic-overlay]').each(function () { 
        var overlay = $(this), target = $(overlay.data('target')); 
        overlay.css('opacity', 0).css('position', 'absolute').offset(target.offset()).width(target.outerWidth()).height(target.outerHeight());
      });
      if ("onwebkitspeechchange"  in document.createElement("input")) {
        var editorOffset = $('#editor').offset();
        $('#voiceBtn').css('position','absolute').offset({top: editorOffset.top, left: editorOffset.left+$('#editor').innerWidth()-35});
      } else {
        $('#voiceBtn').hide();
      }
	};
	function showErrorAlert (reason, detail) {
		var msg='';
		if (reason==='unsupported-file-type') { msg = "Unsupported format " +detail; }
		else {
			console.log("error uploading file", reason, detail);
		}
		$('<div class="alert"> <button type="button" class="close" data-dismiss="alert">&times;</button>'+ 
		 '<strong>File upload error</strong> '+msg+' </div>').prependTo('#alerts');
	};
    initToolbarBootstrapBindings();  
	$('#editor').wysiwyg({ fileUploadError: showErrorAlert} );
    window.prettyPrint && prettyPrint();
  });
</script>
    <script src="js/site.js"></script>
    <script type="text/javascript">
    $(function(){
    	$("#r-self, #r-other").change(function () {
			var checked = $('input[name=author_who]:checked', '#new-file').val();
    		if(checked == "self"){
    			$(".other-div").hide();
    			$("#isSelf").val("yes");
    		}
    		else{
    			$(".other-div").show();
    			$("#isSelf").val("no");
    		}
    	});
    	//callback handler for form submit
		

			function onsuccess(response,status){
				var response = response.split("||");
				if(response[0] != "error"){
					$("#addNewAuthor").modal("hide");
	      	$("#success-author").show();
	      	$("#other-author-id").append(response);
	      	$('#addNewAuthorForm').trigger("reset");
	      }
	      else{
	      	alert("Error: " + response[1]);
	      }
			 }
			 $("#addNewAuthorForm").on('submit',function(){
			  var options={
			   url     : 'execute/add_author.php',
			   success : onsuccess
			  };
			  $(this).ajaxSubmit(options);
			 return false;
			 });
		});
    </script>

	</body>

<!-- Mirrored from wbpreview.com/previews/WB0070A9H/index.htm by HTTrack Website Copier/3.x [XR&CO'2013], Wed, 22 Jan 2014 10:31:21 GMT -->
</html>